package com.csdj.wenjun.config;

import com.csdj.wenjun.service.RedisService;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * web相关的配置类
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Resource
    private RedisService redisService;

    /**
     * 配置拦截器
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor(redisService))
                .addPathPatterns("/**")//需要拦截的路径
                .excludePathPatterns("/user/yzm","/user/login","/user/zhuche","/img/**","/user/selectEmail");//不需要拦截的路径
    }

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/user");

    }
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/img/**").addResourceLocations("file:D:/NZrengli/img/");
    }
}
